<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<label>书名:</label>
		<input type="text" name="book_Name" id="" value="" placeholder="输入书名"/>
		<br>
		<label>价格:</label>
		<input type="text" name="book_Price" id="" value="" placeholder="输入价格"/>
		<br>
		<label>数量:</label>
		<input type="text" name="book_Count" id="" value="" placeholder="输入数量"/>
		<br>
		<input type="button" name="save" id="" onclick="edit()" value="修改"/>
		<script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			let edit_book = JSON.parse(sessionStorage.getItem("edit_book"));
			let arr = JSON.parse(sessionStorage.getItem("edit_arr"));
			let index = JSON.parse(sessionStorage.getItem("index_data"));
			console.log(index);
			if (edit_book){
				$("input[name='book_Name']").val(edit_book.name);
				$("input[name='book_Price']").val(edit_book.price);
				$("input[name='book_Count']").val(edit_book.count);
			}
			function edit(){
				let book_Name = $("input[name='book_Name']").val();
				let book_Price = $("input[name='book_Price']").val();
				let book_Count = $("input[name='book_Count']").val();
				
				let new_edit =
				 {
					id:edit_book.id,
					name:book_Name,
					price:book_Price,
					count:book_Count
				}
				arr.splice(index,1,new_edit);
				localStorage.setItem("new_book",JSON.stringify(arr));
				console.log(arr);
				window.location.href="index.html"
			}
		</script>
	</body>
</html>
